package br.com.unifebe.tcc.componente.GUI;

import java.util.Enumeration;

import javax.swing.DefaultComboBoxModel;

import br.com.unifebe.tcc.model.StringValuedEnum;

public class JMLEnumComboBox<E> extends JMLComboBox {
	private Enumeration items;
	public JMLEnumComboBox(Class enumClass) { 
		super();
		
		setModel(new DefaultComboBoxModel( enumClass.getEnumConstants() ));
		
		init();
	
		
	}
	
	
	
	@Override
	public E getUserObject() {
		return  (E) getSelectedItem();
	}
	
	
	@Override
	public void setUserObject(Object object) {
		if (object instanceof StringValuedEnum) {
			
			setSelectedItem(  object );
			
		} else {
			new ClassCastException("Objeto não é um StringValuedEnum");
		}
	}
	
	
	
//	class StyledComboBoxUI extends BasicComboBoxUI {
//		protected ComboPopup createPopup() {
//			BasicComboPopup popup = new BasicComboPopup(comboBox) {
//				@Override
//				protected Rectangle computePopupBounds(int px,int py,int pw,int ph) {
//					return super.computePopupBounds(px,py,Math.max(comboBox.getPreferredSize().width,pw),ph);
//				}
//			};
//			popup.getAccessibleContext().setAccessibleParent(comboBox);
//			
//			return popup;
//		}
//	}
	

	

}
